package com.mbigger.synchronize;

/**
 * 类锁的第一种形式，static形式
 *
 * @author mbigg
 *
 */
public class SynchronizedClassStatic4 implements Runnable {
    static SynchronizedClassStatic4 instance1 = new SynchronizedClassStatic4();
    static SynchronizedClassStatic4 instance2 = new SynchronizedClassStatic4();

    static int i = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(instance1);
        Thread t2 = new Thread(instance2);
        t1.start();
        t2.start();
        while (t1.isAlive() || t2.isAlive()) {
        }
        System.err.println("finished!");
    }

    public void run() {
        method();
    }

    public static synchronized void method() {
        System.err.println("我是类锁的static形式，我叫：" + Thread.currentThread().getName());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("运行结束，我叫：" + Thread.currentThread().getName());
    }

}
